
package com.wyzz.hr.bo;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.apache.commons.lang.StringUtils;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import com.wyzz.hr.pojo.Emailsend;

public class MimeMailMessageFactory {

	public MimeMailMessageFactory() {
	}

	public static MimeMessage createMailMessage(JavaMailSender mailSender,
			Emailsend send) {
		MimeMessage mimeMessage = mailSender.createMimeMessage();
		try {
			MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
			helper.setFrom(send.getEsFrom());
			if (StringUtils.isNotEmpty(send.getEsTo()))
				helper.setTo(send.getEsTo().split(","));
			if (StringUtils.isNotEmpty(send.getEsCc()))
				helper.setCc(send.getEsCc().split(","));
			helper.setSubject(send.getEsTitle());
			helper.setText(send.getEsContent(), true);
		} catch (MessagingException e) {
		}
		return mimeMessage;
	}
}
